package com.atguigu.webapp.controller.history;



import com.atguigu.common.constant.LoginUserContext;
import com.atguigu.common.result.Result;
import com.atguigu.webapp.service.BrowsingHistoryService;
import com.atguigu.webapp.vo.history.HistoryItemVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@Tag(name = "浏览历史管理")
@RequestMapping("/app/history")
public class BrowsingHistoryController {


    @Autowired
    private BrowsingHistoryService browsingHistoryService;

    @Operation(summary = "获取浏览历史")
    @Parameters({
            @Parameter(name = "current",description = "当前页码",in = ParameterIn.QUERY),
            @Parameter(name = "size",description = "需要查询的数量",in = ParameterIn.QUERY)
    })
    @GetMapping("pageItem")
    private Result<IPage<HistoryItemVo>> page(@RequestParam long current, @RequestParam long size) {
        IPage<HistoryItemVo> voIPage = new Page<>(current,size);
//        不登陆打开注释，注释下两行
//        IPage<HistoryItemVo> itemVoIPage = browsingHistoryService.pageHistoryItemByUserId(voIPage,null);
        IPage<HistoryItemVo> itemVoIPage = browsingHistoryService
                .pageHistoryItemByUserId(voIPage, LoginUserContext.getLoginUser().getUserId());
        return Result.ok(itemVoIPage);
    }
}
